Fix array eos_token_id handling - #1463
Merged
Merged
Conversation
…oose first eos id.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the handling of EOS token ids by converting the former single integer representation into an array throughout the codebase so that the chosen EOS token is preserved.
- The EOS token id field in configuration and related components is now represented as an array (vector).
- Comparisons and kernel launches have been updated to iterate over EOS token ids instead of using a single value.
- Removed obsolete code related to handling a singular EOS token in favor of the new array-based approach.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/smartptrs.h | Removed obsolete EOS array launching function. |
| src/search.cpp | Updated EOS token id checking and beam score updates with iteration over EOS token ids. |
| src/models/logits.{h,cpp} | Removed legacy HandleEOSArray logic adapting EOS token id handling. |
| src/generators.h | Introduced a helper "contains" for EOS array membership checks. |
| src/cuda/* | Updated CUDA kernels and interfaces to support iterating over EOS token ids. |
| src/config.{h,cpp} | Changed EOS token configuration from an int to a vector. Also ensured a default value if unset. |
| src/beam_search_scorer* | Updated scorer APIs and condition checks to support EOS token arrays. |
Comments suppressed due to low confidence (1)
src/config.h:84
- Since the EOS token id is now always handled as an array, consider renaming this field to 'eos_token_ids' to clearly reflect that it holds multiple values.
int eos_token_id{}; // The id of the end-of-stream token.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates the handling of the EOS token ID by converting it from a single integer to an array throughout the codebase, ensuring that multiple EOS tokens can be managed consistently.
- Updated EOS handling in search, logits, CUDA kernels, and beam search scorer components.
- Removed obsolete functions (e.g. LaunchHandleEOSArray) from the device interface and adjusted related CUDA kernel logic.
- Modified configuration parsing to convert a single EOS token into a vector and propagate it appropriately.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/smartptrs.h | Removed the LaunchHandleEOSArray function from DeviceInterface. |
| src/search.cpp | Updated EOS token checks to iterate over the EOS token array using the contains helper. |
| src/models/logits.{h,cpp} | Removed EOS array handling functionality to align with the new array approach. |
| src/generators.h | Added a generic contains function for checking EOS tokens in a container. |
| src/cuda/* | Renamed variables from eos_meet to eos_seen and updated CUDA kernels accordingly. |
| src/config.{h,cpp} | Revised configuration for EOS tokens: now using a vector and converting single values to a one-element vector. |
| src/beam_search_scorer.{h,cpp,cuh,cu} | Updated beam search scorer to accept and process multiple EOS tokens consistently. |
Comments suppressed due to low confidence (3)
src/config.h:85
- [nitpick] Consider renaming 'eos_token_id' to 'eos_token_ids' for clarity and consistency with other parts of the codebase where multiple EOS tokens are handled.
std::vector<int> eos_token_id; // The end-of-stream tokens (when set as a single value it is converted to a vector with one value).
src/beam_search_scorer.cpp:125
- [nitpick] For clarity, ensure that 'eos_token_id_' clearly indicates it is a collection; consider renaming it to 'eos_token_ids_' if it holds multiple values.
if (contains(eos_token_id_, next_token)) {
src/smartptrs.h:122
- Ensure that the removal of 'LaunchHandleEOSArray' from the DeviceInterface is fully propagated to all implementations so that no calling code expects this function.
virtual void LaunchHandleEOSArray(float* /*batch_logits*/, int /*batch_beam_size*/, int /*vocab_size*/, const int32_t* /*eos_token_ids*/, int /*eos_token_ids_count*/) { assert(false); }
Baiju Meswani (baijumeswani)
approved these changes
May 9, 2025
kunal-vaishnavi
approved these changes
May 9, 2025
Baiju Meswani (baijumeswani)
enabled auto-merge (squash)
May 9, 2025 00:31
Ryan Hill (RyanUnderhill)
added a commit
that referenced
this pull request
May 12, 2025
Merged
Baiju Meswani (baijumeswani)
added a commit
that referenced
this pull request
May 14, 2025
Address previous PR review comments from #1470 (#1473) Address QNN specific regressions (#1470) Fix array eos_token_id handling (#1463) Constrained decoding integration (#1381) Remove BF16 CPU from valid GQA configuration (#1469) Avoid adding providers if not requested (#1464) Persist provider options across ClearProviders, AppendProvider where possible (#1454) Fix accuracy issues with Gemma models (#1448) Add bfloat16 support in model builder (#1447) Add final norm for LoRA models (#1446) Update version to 0.8.0-rc3 --------- Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com> Co-authored-by: Nenad Banfic <46795300+nenad1002@users.noreply.github.com> Co-authored-by: Nenad Banfic <nebanfic@microsoft.com> Co-authored-by: Baiju Meswani <bmeswani@microsoft.com> Co-authored-by: Abhishek Jindal <abjindal@microsoft.com> Co-authored-by: Ying Xiong <yingxiong@microsoft.com> Co-authored-by: Michał Moskal <michal@moskal.me> Co-authored-by: Kunal Vaishnavi <kvaishnavi@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous approach to tweak the logit values would change the behavior of continuous decoding models by modifying which eos token id was chosen.
This change turns the EOS token id into an array in all places and preserves which EOS token was chosen in the output.
Fixes Issue #1412